package cm.mefobe.android.telecomcost.entities;

import java.security.InvalidParameterException;
import java.util.ArrayList;

import android.util.Log;

public class DayRange extends Entity{
	
	private Day _firstDay;
	private Day _lastDay;
	
	public DayRange() {
		super();		
	}
	
	public ArrayList<Day> getDays()
	{
		ArrayList<Day> weekDays = new ArrayList<Day>();
		Day firstDay = getFirstDay();
		
		if(firstDay != null)
		{
			while(firstDay.getDayOfMonth() <= getLastDay().getDayOfMonth())
			{
				weekDays.add(firstDay);
				firstDay = new Day(firstDay.getDayOfMonth() + 1,firstDay.getMonthOfYear(),firstDay.getYear());
			}
			
			return weekDays;
		}
		
		throw new InvalidParameterException("cannot get the first day of this day range");
	}
	
	public void printDays()
	{
		Log.i("DayRange","printing days............");
		ArrayList<Day> weekDays = getDays();
		
		int index = 0;
		
		while(index < weekDays.size())
		{
			Log.i("DayRange",weekDays.get(index).toString());
		}
	}
	
	public String getDayRangeLabel()
	{
		return "from " + getFirstDay().getDayOfMonth() + " to " + getLastDay().getDayOfMonth() + " " + getFirstDay().getMonthName() + " " + getFirstDay().getYear();
	}
	
	public DayRange(Day _firstDay, Day _lastDay) {
		super();
		setFirstDay(_firstDay);
		setLastDay(_lastDay);
	}
	
	public void setFirstDay(Day firstDay) {
		if(firstDay == null)
		{
			throw new InvalidParameterException("firstDay cannot be null");
		}
		this._firstDay = firstDay;
	}
	
	public Day getFirstDay() {
		if(_firstDay == null)
		{
			throw new InvalidParameterException("_firstDay not set");
		}
		return _firstDay;
	}
	
	public void setLastDay(Day lastDay) {
		if(lastDay == null)
		{
			throw new InvalidParameterException("_lastDay cannot be null");
		}
		this._lastDay = lastDay;
	}
	
	public Day getLastDay() {
		if(_lastDay == null)
		{
			throw new InvalidParameterException("_lastDay not set");
		}
		return _lastDay;
	}
}
